/**
* 实现数字轮播的效果
* @param index 数字
* @param idname id
* @param index 步进
* @param index 动画时长
*/
function numberRollingstart(index, idname, step, runtime = 1200) {
    let that = this;
    function roll(total, idname, step) {
        let n = 0;
        return function () {
            n = n + step >= total ? total : n + step;
            if (n <= total) {
                document.getElementById(idname).innerHTML = thousandSeparator(n);
            }
        };
    }
    let rolling = roll(index, idname, step);
    runtime = runtime >= 300 ? runtime : 1000;
    let timer;
    for (let i = 0, j = Math.ceil(index / step) + 1; i < j; i++) {
        timer = setTimeout(rolling, (runtime / index) * i * step);
    }
    if (timer) clearTimeout(timer);
}

function thousandSeparator(number) {
    let numbers = number.toString().split("").reverse();
    let segs = [];
    while (numbers.length) segs.push(numbers.splice(0, 3).join(""));
    return segs.join(",").split("").reverse().join("");
}
export { numberRollingstart, thousandSeparator }